package com.baizhi.action;

import com.baizhi.dao.TitleDAO;
import com.baizhi.dao.TitleDAOImpl;
import com.baizhi.entity.Title;
import com.baizhi.service.TitleService;
import com.baizhi.service.TitleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class TitleUpdate extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String title =request.getParameter("title");
        String tag = request.getParameter("tag");
        String text = request.getParameter("text");

        HttpSession session = request.getSession();
        String datetime = (String)session.getAttribute("date");
        String name = (String)session.getAttribute("name");

        TitleDAO ts = new TitleDAOImpl();
        Title title1 = new Title();
        title1.setTitle(title);
        title1.setKeyWord(tag);
        title1.setText(text);
        title1.setDate(datetime);
        title1.setName(name);
        System.out.println("更新"+title1);
        ts.update(title1);

        request.getRequestDispatcher("/myblog.jsp").forward(request,response);
    }
}
